function AddNewShippingAddress(addElement) {
    var pa = document.getElementById("errors");
    pa.innerHTML = "&nbsp;";
    for (var i = 0; i < document.salesOrderForm.shippingAddressId.length; i++)
    {
        if (document.salesOrderForm.shippingAddressId[i].value == -1)
        {
            pa.innerHTML = "Can not add more than one new Shipping Address";
            return;
        }
    }
    shipElement = addElement.name;

    if (document.salesOrderForm.endUser.value == "")
    {
        if (document.salesOrderForm.isEndCustomerShipAddress.checked && Number(document.salesOrderForm.odmId.value) > 0)
        {
            customerId = document.salesOrderForm.odmId.value;
        }
        else
        {
            customerId = document.salesOrderForm.customerId.value;
        }
        newWindow = window.open('addAddress.do?action=AddShippingAddress&customerId=' + customerId, 'shippingAddressPopup', 'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=400,height=400,left=550,top=180,resizable=no');
        newWindow.focus();
    }
    else
    {
        newWindow = window.open('addEndUserAddress.do?action=AddEndUserShippingAddress&endUserId=' + document.salesOrderForm.endUserId.value, 'shippingAddressPopup', 'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=400,height=400,left=550,top=180,resizable=no');
        newWindow.focus();
    }
}


function addShippingAddressIdOption(optionContent, optionValue) {
    document.salesOrderForm.shippingAddressId.add(new Option(optionContent, optionValue));
}

function addShippingAddressContactPerson(shipAddressWithoutContactPerson, strShippingAddress, contactPerson)
{
    document.salesOrderForm.shippingAddress.value = strShippingAddress;
    document.salesOrderForm.shippingAddressId.value = -1;
    document.salesOrderForm.shippingContactPerson.length = 0;
    document.salesOrderForm.shippingContactPerson.length = 2;
    document.salesOrderForm.shippingContactPerson.options[0].text = "--- Select ---";
    document.salesOrderForm.shippingContactPerson.options[0].value = "";
    document.salesOrderForm.shippingContactPerson.options[1].text = contactPerson;
    document.salesOrderForm.shippingContactPerson.options[1].value = contactPerson;
    document.salesOrderForm.shippingContactPerson.value = contactPerson;

    shipContactPerson.length = 2;
    shipAddress.length = 2;

    shipContactPerson[0] = '';
    shipAddress[0] = shipAddressWithoutContactPerson;

    shipContactPerson[1] = contactPerson;
    shipAddress[1] = strShippingAddress;
}

function assignShippingAccount(elementName)
{
    var len = elementName.length;
    for (var i = 0; i < len; i++)
    {
        if (elementName.options[i].selected)
        {
            document.salesOrderForm.shippingMethodName.value = elementName.options[i].innerText;
        }
    }
    if (document.salesOrderForm.shippingMethod.value != -1)
    {
        document.salesOrderForm.shippingAccount.value = elementName.value;
    }
    else if (document.salesOrderForm.shippingMethod.value == -1)
    {
        document.salesOrderForm.shippingAccount.value = '';
        document.salesOrderForm.shippingMethodName.value = '';
    }
}

function openReasonCodes()
{
    newWindow = window.open('reasonCodes.do?action=Show', 'reasonCodesPopup', 'channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,top=0,left=0,height=300,widht=500,resizable=yes');
    newWindow.focus();
}

function assignAddressOfType(elementName, addressType)
{
    var customerpo = document.salesOrderForm["customerPO"];
    var qty = document.salesOrderForm["quantity"];
    var price = document.salesOrderForm["unitPriceAsDouble"];
    var partNo = document.salesOrderForm["manufacturingPartNo"];
    var frieght = document.salesOrderForm["frieghtAsDouble"];
    var misc = document.salesOrderForm["miscAsDouble"];
    var miscName = document.salesOrderForm["miscName"].value;
    var date = document.salesOrderForm["requestDate"];
    var x = eval(document.salesOrderForm["manufacturingPartNo"]);
    var isSample = document.salesOrderForm.isSample.value;


    if (x.name == 'manufacturingPartNo')
    {
        document.salesOrderForm.manufacturingPartNo.disabled = false;
    }
    else
    {
        for (var i = 0; i < x.length; i++)
        {
            x[i].disabled = false;
        }
    }
    var z = eval(document.salesOrderForm["quantity"]);
    if (z.name == 'quantity')
    {
        document.salesOrderForm.quantity.disabled = false;
    }
    else
    {
        for (var j = 0; j < z.length; j++)
        {
            z[j].disabled = false;
        }
    }

    var reqDt = eval(document.salesOrderForm["requestDate"]);
    if (reqDt.name == 'requestDate')
    {
        document.salesOrderForm.requestDate.disabled = false;
    }
    else
    {
        for (var j = 0; j < reqDt.length; j++)
        {
            reqDt[j].disabled = false;
        }
    }
    var pric = eval(document.salesOrderForm["unitPriceAsDouble"]);
    if (pric.name == 'unitPriceAsDouble')
    {
        document.salesOrderForm.unitPriceAsDouble.disabled = false;
    }
    else
    {
        for (var j = 0; j < pric.length; j++)
        {
            pric[j].disabled = false;
        }
    }

    for (var txble = 0; txble < count; txble++)
    {
        var isTaxabl = eval(document.salesOrderForm["isTaxable" + txble]);
        if ((isTaxabl != null) && (isTaxabl.disabled == true))
        {
            if (isSample != 0)
            {
                isTaxabl.disabled = false;
            }
        }
    }
    var y = eval(document.salesOrderForm["lineItemDescription"]);
    if (y.name == 'lineItemDescription')
    {
        document.salesOrderForm.lineItemDescription.disabled = false;
    }
    else
    {
        for (var j = 0; j < y.length; j++)
        {
            y[j].disabled = false;
        }
    }
    var po_lineitem = eval(document.salesOrderForm["poLineItemNo"]);
    if (po_lineitem.name == 'poLineItemNo')
    {
        document.salesOrderForm.poLineItemNo.disabled = false;
    }
    else
    {
        for (var j = 0; j < po_lineitem.length; j++)
        {
            po_lineitem[j].disabled = false;
        }
    }
    var lineitem = eval(document.salesOrderForm["lineItemNo"]);
    if (lineitem.name == 'lineItemNo')
    {
        document.salesOrderForm.lineItemNo.disabled = false;
        ( eval("document.salesOrderForm.zeroPrice" + ( document.salesOrderForm.lineItemNo.value )) ).disabled = false;
    }
    else
    {
        for (var j = 0; j < lineitem.length; j++)
        {
            lineitem[j].disabled = false;
            ( eval("document.salesOrderForm.zeroPrice" + ( document.salesOrderForm.lineItemNo[j].value)) ).disabled = false;
        }
    }

    document.salesOrderForm.shippingAddress.disabled = false;
    document.salesOrderForm.billingAddress.disabled = false;
    document.salesOrderForm.phoneNumber.disabled = false;
    document.salesOrderForm.faxNumber.disabled = false;
    document.salesOrderForm.email.disabled = false;
    document.salesOrderForm.shippingAccount.disabled = false;
    document.salesOrderForm.contactPerson.disabled = false;

    for (var cancl = 0; cancl < count; cancl++)
    {
        var isCancelled = eval(document.salesOrderForm["cancel" + cancl]);
        if (( isCancelled != null ) && ( isCancelled.disabled == true ))
        {
            isCancelled.disabled = false;
        }
    }
    if (document.salesOrderForm.contactPerson.value == -1 || document.salesOrderForm.contactPerson.value == '')
    {
        document.salesOrderForm.phoneNumber.value = "";
        document.salesOrderForm.faxNumber.value = "";
        if (document.salesOrderForm.cellNumber != null)
        {
            document.salesOrderForm.cellNumber.value = "";
        }
        document.salesOrderForm.email.value = "";
    }

    enableCustPartNos();//function
    enablePrices();
    document.salesOrderForm.customerPO.disabled = false;
    document.salesOrderForm.shippingAddress.disabled = false;
    document.salesOrderForm.billingAddress.disabled = false;
    document.salesOrderForm.salesTaxType.disabled = false;
    document.salesOrderForm.miscAsDouble.disabled = false;
    document.salesOrderForm.frieghtAsDouble.disabled = false;
    document.salesOrderForm.salesOrderDate.disabled = false;
    if ("Shipping" == addressType) {
        document.salesOrderForm.action.value = "loadShippingAddress";
    } else {
        document.salesOrderForm.action.value = "loadBillingAddress";
    }

    document.salesOrderForm.submit();
}
function setReadOnlyForFreightInsructions(elementName)
{
    if (elementName.value == "-1")
    {
        freightInstructionLabel.innerText = "Freight Instructions:"
        document.salesOrderForm.freightInstructions.readOnly = true;
        document.salesOrderForm.freightInstructions.value = "";
    }
    if (elementName.value == "-2")
    {
        freightInstructionLabel.innerText = "New Freight Instructions:"
        document.salesOrderForm.freightInstructions.readOnly = false;
        //document.salesOrderForm.freightInstructions.value = "";
    }
    else if (Number(elementName.value) > 0)
    {
        freightInstructionLabel.innerText = "Freight Instructions:"
        document.salesOrderForm.freightInstructions.readOnly = true;
    }
}
function assignFreightInstructions(elementName)
{
    if (elementName.value == "-1")
    {
        freightInstructionLabel.innerText = "Freight Instructions:"
        document.salesOrderForm.freightInstructions.readOnly = true;
        document.salesOrderForm.freightInstructions.value = "";
    }
    if (elementName.value == "-2")
    {
        freightInstructionLabel.innerText = "New Freight Instructions:"
        document.salesOrderForm.freightInstructions.readOnly = false;
        document.salesOrderForm.freightInstructions.value = "";
        document.salesOrderForm.freightInstructions.focus();
    }
    else if (Number(elementName.value) > 0)
    {
        var customerpo = document.salesOrderForm["customerPO"];
        var qty = document.salesOrderForm["quantity"];
        var price = document.salesOrderForm["unitPriceAsDouble"];
        var partNo = document.salesOrderForm["manufacturingPartNo"];
        var frieght = document.salesOrderForm["frieghtAsDouble"];
        var misc = document.salesOrderForm["miscAsDouble"];
        var miscName = document.salesOrderForm["miscName"].value;
        var date = document.salesOrderForm["requestDate"];
        var x = eval(document.salesOrderForm["manufacturingPartNo"]);
        var isSample = document.salesOrderForm.isSample.value;


        if (x.name == 'manufacturingPartNo') {
            document.salesOrderForm.manufacturingPartNo.disabled = false;
        }
        else {
            for (var i = 0; i < x.length; i++) {
                x[i].disabled = false;
            }
        }
        var z = eval(document.salesOrderForm["quantity"]);
        if (z.name == 'quantity') {
            document.salesOrderForm.quantity.disabled = false;
        } else {
            for (var j = 0; j < z.length; j++)
            {
                z[j].disabled = false;
            }
        }

        var reqDt = eval(document.salesOrderForm["requestDate"]);
        if (reqDt.name == 'requestDate') {
            document.salesOrderForm.requestDate.disabled = false;
        }
        else {
            for (var j = 0; j < reqDt.length; j++) {
                reqDt[j].disabled = false;
            }
        }
        var pric = eval(document.salesOrderForm["unitPriceAsDouble"]);
        if (pric.name == 'unitPriceAsDouble') {
            document.salesOrderForm.unitPriceAsDouble.disabled = false;
        }
        else {
            for (var j = 0; j < pric.length; j++) {
                pric[j].disabled = false;
            }
        }

        for (var txble = 0; txble < count; txble++) {
            var isTaxabl = eval(document.salesOrderForm["isTaxable" + txble]);
            if ((isTaxabl != null) && (isTaxabl.disabled == true)) {
                if (isSample != 0)
                {
                    isTaxabl.disabled = false;
                }
            }
        }
        var y = eval(document.salesOrderForm["lineItemDescription"]);
        if (y.name == 'lineItemDescription') {
            document.salesOrderForm.lineItemDescription.disabled = false;
        }
        else {
            for (var j = 0; j < y.length; j++) {
                y[j].disabled = false;
            }
        }
        var po_lineitem = eval(document.salesOrderForm["poLineItemNo"]);
        if (po_lineitem.name == 'poLineItemNo') {
            document.salesOrderForm.poLineItemNo.disabled = false;
        }
        else {
            for (var j = 0; j < po_lineitem.length; j++) {
                po_lineitem[j].disabled = false;
            }
        }
        var lineitem = eval(document.salesOrderForm["lineItemNo"]);
        if (lineitem.name == 'lineItemNo') {
            document.salesOrderForm.lineItemNo.disabled = false;
            (eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo.value))).disabled = false;
        }
        else {
            for (var j = 0; j < lineitem.length; j++) {
                lineitem[j].disabled = false;
                (eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo[j].value))).disabled = false;
            }
        }

        document.salesOrderForm.shippingAddress.disabled = false;
        document.salesOrderForm.billingAddress.disabled = false;
        document.salesOrderForm.phoneNumber.disabled = false;
        document.salesOrderForm.faxNumber.disabled = false;
        document.salesOrderForm.email.disabled = false;
        document.salesOrderForm.shippingAccount.disabled = false;
        document.salesOrderForm.contactPerson.disabled = false;

        for (var cancl = 0; cancl < count; cancl++)
        {
            var isCancelled = eval(document.salesOrderForm["cancel" + cancl]);
            if ((isCancelled != null) && (isCancelled.disabled == true))
            {
                isCancelled.disabled = false;
            }
        }
        if (document.salesOrderForm.contactPerson.value == -1 || document.salesOrderForm.contactPerson.value == '')
        {
            document.salesOrderForm.phoneNumber.value = "";
            document.salesOrderForm.faxNumber.value = "";
            if (document.salesOrderForm.cellNumber != null)
            {
                document.salesOrderForm.cellNumber.value = "";
            }
            document.salesOrderForm.email.value = "";
        }

        enableCustPartNos();
        enablePrices();
        document.salesOrderForm.customerPO.disabled = false;
        document.salesOrderForm.shippingAddress.disabled = false;
        document.salesOrderForm.billingAddress.disabled = false;
        document.salesOrderForm.salesTaxType.disabled = false;
        document.salesOrderForm.miscAsDouble.disabled = false;
        document.salesOrderForm.frieghtAsDouble.disabled = false;
        document.salesOrderForm.salesOrderDate.disabled = false;
        document.salesOrderForm.action.value = "loadFreightInstructions";
        document.salesOrderForm.submit();
    }
}
function getCustomerShippingAddress()
{
    var isEndCustomerShipAddress = document.salesOrderForm["isEndCustomerShipAddress"];

    isEndCustomerShipAddress.checked = false;

    enableFormFields();
    document.salesOrderForm.action.value = "loadEndCustomerDefualtShippingAddress";
    document.salesOrderForm.submit();
}
function enableFormFields()
{
    var customerpo = document.salesOrderForm["customerPO"];
    var qty = document.salesOrderForm["quantity"];
    var price = document.salesOrderForm["unitPriceAsDouble"];
    var partNo = document.salesOrderForm["manufacturingPartNo"];
    var frieght = document.salesOrderForm["frieghtAsDouble"];
    var misc = document.salesOrderForm["miscAsDouble"];
    var miscName = document.salesOrderForm["miscName"].value;
    var date = document.salesOrderForm["requestDate"];
    var x = eval(document.salesOrderForm["manufacturingPartNo"]);
    var isSample = document.salesOrderForm.isSample.value;


    if (x.name == 'manufacturingPartNo') {
        document.salesOrderForm.manufacturingPartNo.disabled = false;
    }
    else {
        for (var i = 0; i < x.length; i++) {
            x[i].disabled = false;
        }
    }
    var z = eval(document.salesOrderForm["quantity"]);
    if (z.name == 'quantity') {
        document.salesOrderForm.quantity.disabled = false;
    } else {
        for (var j = 0; j < z.length; j++)
        {
            z[j].disabled = false;
        }
    }

    var reqDt = eval(document.salesOrderForm["requestDate"]);
    if (reqDt.name == 'requestDate') {
        document.salesOrderForm.requestDate.disabled = false;
    }
    else {
        for (var j = 0; j < reqDt.length; j++) {
            reqDt[j].disabled = false;
        }
    }
    var pric = eval(document.salesOrderForm["unitPriceAsDouble"]);
    if (pric.name == 'unitPriceAsDouble') {
        document.salesOrderForm.unitPriceAsDouble.disabled = false;
    }
    else {
        for (var j = 0; j < pric.length; j++) {
            pric[j].disabled = false;
        }
    }

    for (var txble = 0; txble < count; txble++) {
        var isTaxabl = eval(document.salesOrderForm["isTaxable" + txble]);
        if ((isTaxabl != null) && (isTaxabl.disabled == true)) {
            if (isSample != 0)
            {
                isTaxabl.disabled = false;
            }
        }
    }
    var y = eval(document.salesOrderForm["lineItemDescription"]);
    if (y.name == 'lineItemDescription') {
        document.salesOrderForm.lineItemDescription.disabled = false;
    }
    else {
        for (var j = 0; j < y.length; j++) {
            y[j].disabled = false;
        }
    }
    var po_lineitem = eval(document.salesOrderForm["poLineItemNo"]);
    if (po_lineitem.name == 'poLineItemNo') {
        document.salesOrderForm.poLineItemNo.disabled = false;
    }
    else {
        for (var j = 0; j < po_lineitem.length; j++) {
            po_lineitem[j].disabled = false;
        }
    }
    var lineitem = eval(document.salesOrderForm["lineItemNo"]);
    if (lineitem.name == 'lineItemNo') {
        document.salesOrderForm.lineItemNo.disabled = false;
        (eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo.value))).disabled = false;
    }
    else {
        for (var j = 0; j < lineitem.length; j++) {
            lineitem[j].disabled = false;
            (eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo[j].value))).disabled = false;
        }
    }

    document.salesOrderForm.shippingAddress.disabled = false;
    document.salesOrderForm.billingAddress.disabled = false;
    document.salesOrderForm.phoneNumber.disabled = false;
    document.salesOrderForm.faxNumber.disabled = false;
    document.salesOrderForm.email.disabled = false;
    document.salesOrderForm.shippingAccount.disabled = false;
    document.salesOrderForm.contactPerson.disabled = false;

    for (var cancl = 0; cancl < count; cancl++) {
        var isCancelled = eval(document.salesOrderForm["cancel" + cancl]);
        if ((isCancelled != null) && (isCancelled.disabled == true)) {
            isCancelled.disabled = false;
        }
    }
    if (document.salesOrderForm.contactPerson.value == -1 || document.salesOrderForm.contactPerson.value == '') {
        document.salesOrderForm.phoneNumber.value = "";
        document.salesOrderForm.faxNumber.value = "";
        if (document.salesOrderForm.cellNumber != null) {
            document.salesOrderForm.cellNumber.value = "";
        }
        document.salesOrderForm.email.value = "";
    }

    enableCustPartNos();
    enablePrices();
    document.salesOrderForm.customerPO.disabled = false;
    document.salesOrderForm.shippingAddress.disabled = false;
    document.salesOrderForm.billingAddress.disabled = false;
    document.salesOrderForm.salesTaxType.disabled = false;
    document.salesOrderForm.miscAsDouble.disabled = false;
    document.salesOrderForm.frieghtAsDouble.disabled = false;
    document.salesOrderForm.salesOrderDate.disabled = false;
}
function dateValidation() {
    var dateValue = "";
    var temp = document.salesOrderForm["requestDate"];

    if (temp.length == null) {

        if (chkDate(temp.value, "Requested Dock Date", "Y") == false) {
            errors = errMsg;
            temp.select();
            temp.focus();
        }
        else {
            return false;
        }
    } else {
        var partNo = document.salesOrderForm["manufacturingPartNo"];
        var i;
        for (i = 0; i < temp.length; i++) {
            if (partNo[i].value != '') {
                if (chkDate(temp[i].value, "Requested Dock Date ", "Y") == false) {
                    errors = errMsg;
                    temp[i].select();
                    temp[i].focus();
                    break;
                }
            }
        }
    }

    if (errors != '') {
        return false;
    } else {
        return true;
    }
}

function validateRequestDate(temp) {
    errors = "";
    validateDate(temp.value);
    var pa = document.getElementById("errors");
    pa.innerHTML = errors;
    return;
}
function enableCustPartNos()
{
    var custPNo = eval('document.salesOrderForm.customerPartNo');
    if (custPNo.length == null)
    {
        custPNo.disabled = false;
    }
    else
    {
        for (var xx = 0; xx < custPNo.length; xx++)
        {
            custPNo[xx].disabled = false;
        }
    }
}
function enablePrices()
{
    if (isSample == 0)
    {
        var price = document.salesOrderForm["unitPriceAsDouble"];
        var lineitem = eval(document.salesOrderForm["lineItemNo"]);
        if (lineitem.name == 'lineItemNo')
        {
            var element1 = eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo.value));
            var element2 = eval("document.salesOrderForm.expediteFee" + ( document.salesOrderForm.lineItemNo.value - 1 ));
            price.disabled = false;
            element1.disabled = false;
            if (element2 = ! 'undefined')
            {
                element2.disabled = false;
            }
        }
        else
        {
            for (var i = 0; i < lineitem.length; i++)
            {
                var element1 = eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo[i].value));
                var element2 = eval("document.salesOrderForm.expediteFee" + (document.salesOrderForm.lineItemNo[i].value - 1 ));
                price[i].disabled = false;
                element1.disabled = false;
                if (element2 = ! 'undefined')
                {
                    element2.disabled = false;
                }
            }
        }
    }
}


function enableLabelNumbers()
{
    var labelNo = eval('document.salesOrderForm.labelNumber');
    if (labelNo.length == null)
    {
        labelNo.disabled = false;
    }
    else
    {
        for (var xx = 0; xx < labelNo.length; xx++)
        {
            labelNo[xx].disabled = false;
        }
    }
}
function AddShippingTerms()
{
    var shippinglabel = document.getElementById("newShippingTerms");
    var letterOfCreditNoObj = document.getElementById("letterOfCreditNo");
    var lcIssuingBankObj = document.getElementById("lcIssuingBank");

    if (document.salesOrderForm.shippingTerms.value == -2)
    {
        document.salesOrderForm.newShippingTerms.style.visibility = "visible";
        document.salesOrderForm.newShippingTerms.value = '';
        shippinglabel.innerHTML = "New Pay Terms : ";
    }
    else
    {
        document.salesOrderForm.newShippingTerms.style.visibility = "hidden";
        shippinglabel.innerHTML = "";
    }
}
function setZeroPrice(no, lineno)
{
    if (document.salesOrderForm.quantity.length != null)
    {
        var element = eval(document.salesOrderForm["zeroPrice" + lineno]);
        if (element.checked == true)
        {
            document.salesOrderForm.unitPriceAsDouble[no].value = "0.0";
        }
    }
    else
    {
        if (eval("document.salesOrderForm.zeroPrice" + lineno).checked == true)
        {
            document.salesOrderForm.unitPriceAsDouble.value = "0.0";
        }
    }
}

function disableIfChecked(canclno, lineno)
{
    var pa = document.getElementById("errors");
    var isSample = document.salesOrderForm.isSample.value;

    if (document.salesOrderForm.quantity.length != null)
    {
        var cancl = eval(document.salesOrderForm["cancel" + canclno]);

        if ((cancl != null) && ( cancl.checked == true ))
        {
            if (document.salesOrderForm.issueStatus[canclno].value == 'ISSUED')
            {
                document.salesOrderForm.errorStatus[canclno].value = "Can't cancel lineitem&nbsp;" + lineno + "&nbsp;as Packing Slip issued";
                pa.innerHTML = "<li> Cannot cancel a line item against which Packing Slip is issued";
                return;
            }

            document.salesOrderForm.quantity[canclno].disabled = true;
            document.salesOrderForm.unitPriceAsDouble[canclno].disabled = true;
            document.salesOrderForm.requestDate[canclno].disabled = true;
            document.salesOrderForm.lineItemDescription[canclno].disabled = true;

            eval("document.salesOrderForm.isTaxable" + lineno).disabled = true;
            eval("document.salesOrderForm.zeroPrice" + lineno).disabled = true;
        }
        else
        {
            if (document.salesOrderForm.issueStatus[canclno].value == 'ISSUED')
            {
                pa.innerHTML = "";
                document.salesOrderForm.errorStatus[canclno].value = "";
                return;
            }

            if (document.salesOrderForm.checkStatus[canclno].value == 'PARTIALLY SHIPPED')
            {
                return;
            }

            document.salesOrderForm.quantity[canclno].disabled = false;
            document.salesOrderForm.requestDate[canclno].disabled = false;
            document.salesOrderForm.lineItemDescription[canclno].disabled = false;
            if (isSample != 0)
            {
                document.salesOrderForm.unitPriceAsDouble[canclno].disabled = false;
                eval("document.salesOrderForm.isTaxable" + lineno).disabled = false;
                eval("document.salesOrderForm.zeroPrice" + lineno).disabled = false;
            }
        }
    }
    else
    {
        if ((document.salesOrderForm.cancel0 != null) && ( document.salesOrderForm.cancel0.checked == true ))
        {
            if (document.salesOrderForm.issueStatus.value == 'ISSUED')
            {
                document.salesOrderForm.errorStatus.value = "Can't cancel lineitem&nbsp;" + lineno + "&nbsp;as Packing Slip issued";
                pa.innerHTML = "<li> Cannot cancel a line item against which Packing Slip is issued";
                return;
            }

            document.salesOrderForm.quantity.disabled = true;
            document.salesOrderForm.unitPriceAsDouble.disabled = true;
            document.salesOrderForm.requestDate.disabled = true;
            document.salesOrderForm.lineItemDescription.disabled = true;
            eval("document.salesOrderForm.isTaxable" + lineno).disabled = true;
            eval("document.salesOrderForm.zeroPrice" + lineno).disabled = true;
        }
        else
        {
            if (document.salesOrderForm.issueStatus.value == 'ISSUED')
            {
                pa.innerHTML = "";
                document.salesOrderForm.errorStatus.value = "";
                return;
            }

            if (document.salesOrderForm.checkStatus.value == 'PARTIALLY SHIPPED')
            {
                return;
            }

            document.salesOrderForm.quantity.disabled = false;
            document.salesOrderForm.requestDate.disabled = false;
            document.salesOrderForm.lineItemDescription.disabled = false;

            if (isSample != 0)
            {
                document.salesOrderForm.unitPriceAsDouble.disabled = false;
                eval("document.salesOrderForm.isTaxable" + lineno).disabled = false;
                eval("document.salesOrderForm.zeroPrice" + lineno).disabled = false;
            }

        }
    }
}

function checkBaseOrderQty(selecteditem)
{
    var form = document.salesOrderForm;
    var mfPartNo;
    var size;
    size = keys.length;
    var lineitems = count;
    var qty;
    var i;
    var tempQty;
    var lQty;
    var gQty;
    var tempBaseOrderQty;
    var lineItemNo;
    errors = '';
    var message = ''
    var paMessage = document.getElementById("message");

    if (document.salesOrderForm["quantity"].length != null)
    {
        mfPartNo = form.manufacturingPartNo[selecteditem].value;
        mfPartNo = trim(mfPartNo.toLowerCase());
        qty = Number(trim(form.quantity[selecteditem].value));
        lineItemNo = form.lineItemNo[selecteditem].value;
    }
    else
    {
        mfPartNo = form.manufacturingPartNo.value;
        mfPartNo = trim(mfPartNo.toLowerCase());
        qty = Number(trim(form.quantity.value));
        lineItemNo = form.lineItemNo.value;
    }
    for (i = 0; i < size; i++)
    {
        if (mfPartNo == trim(keys[i].toLowerCase()) && baseOrderQty[i] != 'null' && baseOrderQty[i] != '')
        {
            if (isNaN(qty) || isNaN(baseOrderQty[i]))
            {
                return;
            }
            else
            {
                tempBaseOrderQty = Number(baseOrderQty[i]);

                if (tempBaseOrderQty != 0)
                {
                    if (qty > tempBaseOrderQty)
                    {
                        tempQty = qty % tempBaseOrderQty;
                        if (tempQty != 0)
                        {
                            for (j = qty; ; j++)
                            {
                                if (j % tempBaseOrderQty == 0)
                                {
                                    gQty = j;
                                    break;
                                }
                            }
                            for (j = qty; ; j--)
                            {
                                if (j % tempBaseOrderQty == 0)
                                {
                                    lQty = j;
                                    break;
                                }
                            }
                            message = message + '<br>' + "<li>Note: Line Item " + lineItemNo + " Quantity is not multiple of the Base Order Quantity (" + tempBaseOrderQty + ") of this Product. The nearest quantities are " + lQty + " and " + gQty + ".";
                            paMessage.innerHTML = message;

                            return;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else if (qty < tempBaseOrderQty)
                    {
                        message = message + '<br>' + "<li>Note: Line Item " + lineItemNo + " Quantity is not multiple of the Base Order Quantity (" + tempBaseOrderQty + ") of this Product. The nearest quantity is " + tempBaseOrderQty + ".";
                        paMessage.innerHTML = message;

                        return;
                    }
                }
                else
                {
                    message = '';
                    paMessage.innerHTML = message;
                    return;
                }
            }
        }
    }
}


function getComments(selecteditem)
{
    errors = "";
    var isMultipleItems = true;
    if (document.salesOrderForm["quantity"].length == null)
    {
        isMultipleItems = false;
    }
    if (isMultipleItems)
        document.salesOrderForm.lineItemDescription[selecteditem].value = "";
    else
        document.salesOrderForm.lineItemDescription.value = "";
    var form = document.salesOrderForm;
    var mfPartNo;
    var size;
    size = keys.length;

    var custPartNosOptions = (isMultipleItems) ? form.customerPartNo[selecteditem].options : form.customerPartNo.options;
    var custPartNosOptionsLen = custPartNosOptions.length;
    for (var l = custPartNosOptionsLen - 1; l >= 0; l--)
    {
        custPartNosOptions[l] = null;
    }
    custPartNosOptions[0] = new Option("Select Customer Part No", "");
    mfPartNo = (isMultipleItems) ? form.manufacturingPartNo[selecteditem].value : form.manufacturingPartNo.value;
    mfPartNo = trim(mfPartNo.toLowerCase());
    for (var i = 0; i < size; i++)
    {
        if (mfPartNo == trim(keys[i].toLowerCase()))
        {
            var tmpCustomerNos = customernos[i];
            for (var k = 0; k < tmpCustomerNos.length; k++)
            {
                if (tmpCustomerNos[k] != '')
                {
                    custPartNosOptions[k + 1] = new Option(tmpCustomerNos[k], tmpCustomerNos[k]);
                }
            }
            break;
        }
    }
    custPartNosOptions[tmpCustomerNos.length + 1] = new Option("--Add New CustomerPart No--", "-2");
    for (i = 0; i < size; i++)
    {
        if (mfPartNo == trim(keys[i].toLowerCase()) && comments[i] != 'null')
        {
            if (isMultipleItems)
                form.lineItemDescription[selecteditem].value = comments[i];
            else
                form.lineItemDescription.value = comments[i];
            break;
        }
        else
        {
            if (isMultipleItems)
                form.lineItemDescription[selecteditem].value = "";
            else
                form.lineItemDescription.value = "";
        }
    }
    showHideNewCustPartNo(selecteditem);
}
function selectContactPerson(element, idValue, indexValue)
{
    var yy = document.salesOrderForm.contactPerson.selectedIndex;
    if (element == 'CustomerContactPerson')
    {
        for (ss = 0; ss < customerContactPerson.length; ss++)
        {
            if (document.salesOrderForm.contactPerson.value == customerContactPerson[ss])
            {
                document.salesOrderForm.contactPerson.value = customerContactPerson[ss];
                document.salesOrderForm.phoneNumber.value = customerPhNo[ss];
                document.salesOrderForm.cellNumber.value = customerCellNo[ss];
                document.salesOrderForm.faxNumber.value = customerFax[ss];
                document.salesOrderForm.email.value = customerEmail[ss];

                document.salesOrderForm.phoneNumber.disabled = false;
                document.salesOrderForm.cellNumber.disabled = false;
                document.salesOrderForm.faxNumber.disabled = false;
                document.salesOrderForm.email.disabled = false;
                if (document.salesOrderForm.customerName.value == customerContactPerson[ss])
                {
                    document.salesOrderForm.cellNumber.disabled = true;
                }
            }
            else if (document.salesOrderForm.contactPerson.value == '')
            {
                document.salesOrderForm.contactPerson.value = '';
                document.salesOrderForm.phoneNumber.value = '';
                document.salesOrderForm.cellNumber.value = '';
                document.salesOrderForm.faxNumber.value = '';
                document.salesOrderForm.email.value = '';

                document.salesOrderForm.phoneNumber.disabled = true;
                document.salesOrderForm.cellNumber.disabled = true;
                document.salesOrderForm.faxNumber.disabled = true;
                document.salesOrderForm.email.disabled = true;
            }
        }
    }
    var ww = document.salesOrderForm.billingContactPerson.selectedIndex;
    if (element == 'BillingContactPerson')
    {
        for (pp = 0; pp < billContactPerson.length; pp++)
        {
            if (document.salesOrderForm.billingContactPerson.value == billContactPerson[pp])
            {
                document.salesOrderForm.billingContactPerson.value = billContactPerson[pp];

                document.salesOrderForm.billingAddress.value = billAddress[pp].replace(/~/g, '\n');
            }
        }

    }
    if (element == 'ShippingContactPerson')
    {
        for (ff = 0; ff < shipContactPerson.length; ff++)
        {
            if (document.salesOrderForm.shippingContactPerson.value == shipContactPerson[ff])
            {
                document.salesOrderForm.shippingContactPerson.value = shipContactPerson[ff];
                document.salesOrderForm.shippingAddress.value = shipAddress[ff].replace(/~/g, '\n');
            }
        }
    }

}


function selectEndUser()
{
    var endUserId = document.salesOrderForm.endUserId.value;
    var isSample = document.salesOrderForm.isSample.value;

    if (endUserId != -1)
    {
        var lineitem = eval(document.salesOrderForm["lineItemNo"]);
        if (lineitem.name == 'lineItemNo')
        {
            document.salesOrderForm.lineItemNo.disabled = false;
            (eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo.value))).disabled = false;
        }
        else
        {
            for (var j = 0; j < lineitem.length; j++)
            {
                lineitem[j].disabled = false;
                (eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo[j].value))).disabled = false;
            }
        }

        var po_lineitem = eval(document.salesOrderForm["poLineItemNo"]);
        if (po_lineitem.name == 'poLineItemNo')
        {
            document.salesOrderForm.poLineItemNo.disabled = false;
        }
        else
        {
            for (var j = 0; j < po_lineitem.length; j++)
            {
                po_lineitem[j].disabled = false;
            }
        }

        var mfgValue = eval(document.salesOrderForm["manufacturingPartNo"]);
        if (mfgValue.name == 'manufacturingPartNo')
        {

            document.salesOrderForm.manufacturingPartNo.disabled = false;
        }
        else
        {
            for (var i = 0; i < mfgValue.length; i++)
            {
                mfgValue[i].disabled = false;
            }
        }

        var z = eval(document.salesOrderForm["quantity"]);
        if (z.name == 'quantity')
        {
            document.salesOrderForm.quantity.disabled = false;
        }
        else
        {
            for (var j = 0; j < z.length; j++)
            {
                z[j].disabled = false;
            }
        }

        var reqDt = eval(document.salesOrderForm["requestDate"]);
        if (reqDt.name == 'requestDate')
        {
            document.salesOrderForm.requestDate.disabled = false;
        }
        else
        {
            for (var j = 0; j < reqDt.length; j++)
            {
                reqDt[j].disabled = false;
            }
        }

        var pric = eval(document.salesOrderForm["unitPriceAsDouble"]);
        if (pric.name == 'unitPriceAsDouble')
        {
            document.salesOrderForm.unitPriceAsDouble.disabled = false;
        }
        else
        {
            for (var j = 0; j < pric.length; j++)
            {
                pric[j].disabled = false;
            }
        }

        for (var txble = 0; txble < count; txble++)
        {
            var isTaxabl = eval(document.salesOrderForm["isTaxable" + txble]);
            if ((isTaxabl != null) && (isTaxabl.disabled == true))
            {
                if (isSample != 0)
                {
                    isTaxabl.disabled = false;
                }
            }
        }

        var y = eval(document.salesOrderForm["lineItemDescription"]);
        if (y.name == 'lineItemDescription')
        {
            document.salesOrderForm.lineItemDescription.disabled = false;
        }
        else
        {
            for (var j = 0; j < y.length; j++)
            {
                y[j].disabled = false;
            }
        }

        enableCustPartNos();
        enablePrices();
        document.salesOrderForm.customerPO.disabled = false;
        document.salesOrderForm.shippingAddress.disabled = false;
        document.salesOrderForm.billingAddress.disabled = false;

        document.salesOrderForm.salesTaxType.disabled = false;
        document.salesOrderForm.miscAsDouble.disabled = false;
        document.salesOrderForm.frieghtAsDouble.disabled = false;
        document.salesOrderForm.salesOrderDate.disabled = false;
        document.salesOrderForm.action.value = 'loadEndUserDetails';
        document.salesOrderForm.submit();
    }
}

function selectODM()
{
    var odmId = document.salesOrderForm.odmId.value;
    var isSample = document.salesOrderForm.isSample.value;

    var lineitem = eval(document.salesOrderForm["lineItemNo"]);
    if (lineitem.name == 'lineItemNo')
    {
        document.salesOrderForm.lineItemNo.disabled = false;
        (eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo.value))).disabled = false;
    }
    else
    {
        for (var j = 0; j < lineitem.length; j++)
        {
            lineitem[j].disabled = false;
            (eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo[j].value))).disabled = false;
        }
    }

    var po_lineitem = eval(document.salesOrderForm["poLineItemNo"]);
    if (po_lineitem.name == 'poLineItemNo')
    {
        document.salesOrderForm.poLineItemNo.disabled = false;
    }
    else
    {
        for (var j = 0; j < po_lineitem.length; j++)
        {
            po_lineitem[j].disabled = false;
        }
    }

    var mfgValue = eval(document.salesOrderForm["manufacturingPartNo"]);
    if (mfgValue.name == 'manufacturingPartNo')
    {

        document.salesOrderForm.manufacturingPartNo.disabled = false;
    }
    else
    {
        for (var i = 0; i < mfgValue.length; i++)
        {
            mfgValue[i].disabled = false;
        }
    }

    var z = eval(document.salesOrderForm["quantity"]);
    if (z.name == 'quantity')
    {
        document.salesOrderForm.quantity.disabled = false;
    }
    else
    {
        for (var j = 0; j < z.length; j++)
        {
            z[j].disabled = false;
        }
    }

    var reqDt = eval(document.salesOrderForm["requestDate"]);
    if (reqDt.name == 'requestDate')
    {
        document.salesOrderForm.requestDate.disabled = false;
    }
    else
    {
        for (var j = 0; j < reqDt.length; j++)
        {
            reqDt[j].disabled = false;
        }
    }
    var pric = eval(document.salesOrderForm["unitPriceAsDouble"]);
    if (pric.name == 'unitPriceAsDouble')
    {
        document.salesOrderForm.unitPriceAsDouble.disabled = false;
    }
    else
    {
        for (var j = 0; j < pric.length; j++)
        {
            pric[j].disabled = false;
        }
    }

    for (var txble = 0; txble < count; txble++)
    {
        var isTaxabl = eval(document.salesOrderForm["isTaxable" + txble]);
        if ((isTaxabl != null) && (isTaxabl.disabled == true))
        {
            if (isSample != 0)
            {
                isTaxabl.disabled = false;
            }
        }
    }

    var y = eval(document.salesOrderForm["lineItemDescription"]);
    if (y.name == 'lineItemDescription')
    {
        document.salesOrderForm.lineItemDescription.disabled = false;
    }
    else
    {
        for (var j = 0; j < y.length; j++)
        {
            y[j].disabled = false;
        }
    }

    enableCustPartNos();
    enablePrices();

    document.salesOrderForm.customerPO.disabled = false;
    document.salesOrderForm.shippingAddress.disabled = false;
    document.salesOrderForm.billingAddress.disabled = false;

    document.salesOrderForm.salesTaxType.disabled = false;
    document.salesOrderForm.miscAsDouble.disabled = false;
    document.salesOrderForm.frieghtAsDouble.disabled = false;
    document.salesOrderForm.salesOrderDate.disabled = false;

    document.salesOrderForm.action.value = 'loadODMDetails';
    document.salesOrderForm.submit();
}

function splitLineItems()
{
    var customerpo = document.salesOrderForm["customerPO"];
    var qty = document.salesOrderForm["quantity"];
    var price = document.salesOrderForm["unitPriceAsDouble"];
    var partNo = document.salesOrderForm["manufacturingPartNo"];
    var frieght = document.salesOrderForm["frieghtAsDouble"];
    var misc = document.salesOrderForm["miscAsDouble"];
    var miscName = document.salesOrderForm["miscName"].value;
    var date = document.salesOrderForm["requestDate"];
    var x = eval(document.salesOrderForm["manufacturingPartNo"]);
    var isSample = document.salesOrderForm.isSample.value;

    if (x.name == 'manufacturingPartNo') {
        document.salesOrderForm.manufacturingPartNo.disabled = false;
    }
    else {
        for (var i = 0; i < x.length; i++) {
            x[i].disabled = false;
        }
    }
    var z = eval(document.salesOrderForm["quantity"]);
    if (z.name == 'quantity') {
        document.salesOrderForm.quantity.disabled = false;
    } else {
        for (var j = 0; j < z.length; j++)
        {
            z[j].disabled = false;
        }
    }

    var reqDt = eval(document.salesOrderForm["requestDate"]);
    if (reqDt.name == 'requestDate') {
        document.salesOrderForm.requestDate.disabled = false;
    }
    else {
        for (var j = 0; j < reqDt.length; j++) {
            reqDt[j].disabled = false;
        }
    }
    var pric = eval(document.salesOrderForm["unitPriceAsDouble"]);
    if (pric.name == 'unitPriceAsDouble') {
        document.salesOrderForm.unitPriceAsDouble.disabled = false;
    }
    else {
        for (var j = 0; j < pric.length; j++) {
            pric[j].disabled = false;
        }
    }

    for (var txble = 0; txble < count; txble++) {
        var isTaxabl = eval(document.salesOrderForm["isTaxable" + txble]);
        if ((isTaxabl != null) && (isTaxabl.disabled == true)) {
            if (isSample != 0)
            {
                isTaxabl.disabled = false;
            }
        }
    }
    var y = eval(document.salesOrderForm["lineItemDescription"]);
    if (y.name == 'lineItemDescription') {
        document.salesOrderForm.lineItemDescription.disabled = false;
    }
    else {
        for (var j = 0; j < y.length; j++) {
            y[j].disabled = false;
        }
    }
    var po_lineitem = eval(document.salesOrderForm["poLineItemNo"]);
    if (po_lineitem.name == 'poLineItemNo') {
        document.salesOrderForm.poLineItemNo.disabled = false;
    }
    else {
        for (var j = 0; j < po_lineitem.length; j++) {
            po_lineitem[j].disabled = false;
        }
    }
    var lineitem = eval(document.salesOrderForm["lineItemNo"]);
    if (lineitem.name == 'lineItemNo') {
        document.salesOrderForm.lineItemNo.disabled = false;
        (eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo.value))).disabled = false;
    }
    else {
        for (var j = 0; j < lineitem.length; j++) {
            lineitem[j].disabled = false;
            (eval("document.salesOrderForm.zeroPrice" + (document.salesOrderForm.lineItemNo[j].value))).disabled = false;
        }
    }
    document.salesOrderForm.customerPO.disabled = false;
    document.salesOrderForm.shippingAddress.disabled = false;
    document.salesOrderForm.billingAddress.disabled = false;
    document.salesOrderForm.phoneNumber.disabled = false;
    document.salesOrderForm.faxNumber.disabled = false;
    document.salesOrderForm.email.disabled = false;
    document.salesOrderForm.shippingAccount.disabled = false;
    document.salesOrderForm.contactPerson.disabled = false;

    document.salesOrderForm.salesTaxType.disabled = false;
    document.salesOrderForm.miscAsDouble.disabled = false;
    document.salesOrderForm.frieghtAsDouble.disabled = false;
    document.salesOrderForm.salesOrderDate.disabled = false;

    for (var cancl = 0; cancl < count; cancl++) {
        var isCancelled = eval(document.salesOrderForm["cancel" + cancl]);
        if ((isCancelled != null) && (isCancelled.disabled == true)) {
            isCancelled.disabled = false;
        }
    }
    if (document.salesOrderForm.contactPerson.value == -1 || document.salesOrderForm.contactPerson.value == '')
    {
        document.salesOrderForm.phoneNumber.value = "";
        document.salesOrderForm.faxNumber.value = "";
        if (document.salesOrderForm.cellNumber != null)
        {
            document.salesOrderForm.cellNumber.value = "";
        }
        document.salesOrderForm.email.value = "";
    }
    enableCustPartNos();
    enablePrices();

    document.salesOrderForm.action.value = "splitLineItems";
    document.salesOrderForm.splitLineItems.value = "yes";
    document.salesOrderForm.submit();
}
function addOptionToSelect(aName, aValue)
{
    var salesPersonObj = document.salesOrderForm.salesPerson;

    addOption(salesPersonObj, aName + "", aValue, salesPersonObj.options.length);
    for (var i = 0; i < salesPersonObj.options.length; i++)
    {
        if (salesPersonObj.options[i].value == document.salesOrderForm.salesPersonName.value)
        {
            salesPersonObj.options[i].selected = true;
        }
    }
}

function addOption(aSelect, aName, aValue, anIndex)
{
    var aOption = new Option(aName, aValue)
    aSelect.options[anIndex] = aOption;
}

function deleteAllOptions()
{

    var salesPersonObj = document.salesOrderForm.salesPerson;
    var optionValue1 = document.salesOrderForm.salesPerson.value;

    if (typeof salesPersonObj != 'undefined')
    {
        for (var j = salesPersonObj.options.length; j >= 0; j--)
        {
            salesPersonObj.options[j] = null;
        }
    }
}
function showHideNewEndUserField()
{
    var form = document.salesOrderForm;
    var endUserCtrl = form.endCustomerId;
    var newEndUserNameCtrl = form.newEndUserName;
    var endUserLabelSpan = document.getElementById("endUserLabelSpan");
    var endUserTxfieldSpan = document.getElementById("endUserTxfieldSpan");
    if (endUserCtrl.value == "-2")
    {
        endUserLabelSpan.style.display = 'block'
        endUserTxfieldSpan.style.display = 'block'
    }
    else
    {
        newEndUserNameCtrl.value = "";
        endUserLabelSpan.style.display = 'none'
        endUserTxfieldSpan.style.display = 'none'
    }
}
function resetForm()
{
    document.salesOrderForm.reset();
    showHideNewEndUserField();
    showHideNewCustPartNo(-1);
}
function showHideNewCustPartNo(selectedIdx)
{
    var form = document.salesOrderForm;
    if (count > 2)
    {
        if (selectedIdx < 0) //All
        {
            for (var k = 0; k < form.customerPartNo.length; k++)
            {
                if (form.customerPartNo[k].value == "-2")
                {
                    form.newCustomerPartNo[k].style.display = "block";
                    form.newCustomerPartNo[k].focus();
                }
                else
                {
                    form.newCustomerPartNo[k].style.display = "none";
                }
            }
        }
        else
        {
            if (form.customerPartNo[selectedIdx].value == "-2")
            {
                form.newCustomerPartNo[selectedIdx].style.display = "block";
                form.newCustomerPartNo[selectedIdx].focus();
            }
            else
            {
                form.newCustomerPartNo[selectedIdx].style.display = "none";
            }
        }
    }
    else
    {
        if (form.customerPartNo.value == "-2")
        {
            form.newCustomerPartNo.style.display = "block";
            form.newCustomerPartNo.focus();
        }
        else
        {
            form.newCustomerPartNo.style.display = "none";
        }
    }
}
function deleteAllListOptions(listCtrl)
{
    if (typeof listCtrl != 'undefined')
    {
        for (var j = listCtrl.options.length; j >= 0; j--)
        {
            listCtrl.options[j] = null;
        }
    }
}
function addOptionToList(listCtrl, aName, aValue)
{
    addOption(listCtrl, aName, aValue, listCtrl.options.length)
}
function checkValidity(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if (field == 'Contact Person') {
        field_vlaue = document.salesOrderForm.contactPerson.value;
        field_focus = "contactPerson";
    }

    if (field == 'Sales Person') {
        field_vlaue = document.salesOrderForm.salesPerson.value;
        field_focus = "salesPerson";
    }

    if (field == 'Regional Rep') {
        field_vlaue = document.salesOrderForm.regionalRep.value;
        field_focus = "regionalRep";
    }

    if (field == 'End User') {
        field_vlaue = document.salesOrderForm.endUser.value;
        field_focus = "endUser";
    }

    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")"))
        {
            var errMsg = "<li> " + field + " cannot contain #,$,(, and )  Characters";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkSalesCustomer(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if (field == 'Sales Order No') {
        field_vlaue = document.salesOrderForm.salesOrderNo.value;
        field_focus = "salesOrderNo";
    }

    if (field == 'Customer PO No') {
        field_vlaue = document.salesOrderForm.customerPO.value;
        field_focus = "customerPO";
    }

    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")") || (str == "&") || (str == ".") || (str == ",") || (str == " "))
        {
            var errMsg = "<li> " + field + " cannot contain # $ ( ) . , & and space Characters";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkCustomerPONumber(field)
{
    var field_vlaue = document.salesOrderForm.customerPO.value;
    var field_focus = "customerPO";
    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if (i == 0 && str == " ")
        {
            var errMsg = "* " + field + " cannot start with a space";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")") || (str == "&") || (str == ".") || (str == ","))
        {
            var errMsg = "<li> " + field + " cannot contain # $ ( ) . , and &";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkShipping(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if (field == 'Shipping Account') {
        field_vlaue = document.salesOrderForm.shippingAccount.value;
        field_focus = "shippingAccount";
    }

    if (field == 'New Shipping Method') {
        field_vlaue = document.salesOrderForm.newshippingMethod.value;
        field_focus = "newshippingMethod";
    }

    if (field == 'New Shipping Account') {
        field_vlaue = document.salesOrderForm.newshippingAccount.value;
        field_focus = "newshippingAccount";
    }

    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")") || (str == "&") || (str == ".") || (str == ","))
        {
            var errMsg = "<li> " + field + " cannot contain # $ ( ) . , and & Characters";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkForDot(field)
{
    var field_vlaue = document.salesOrderForm.shippingTerms.value;
    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "."))
        {
            var errMsg = "<li> " + field + " cannot contain . Character";
            pa.innerHTML = errMsg;
            document.salesOrderForm.shippingTerms.focus();
            return false;
        }
    }
}

function checkForBraces(field)
{
    var field_vlaue = document.salesOrderForm.deliveryTerms.value;
    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "(") || (str == ")"))
        {
            var errMsg = "<li> " + field + " cannot contain '(' and ')' Characters";
            pa.innerHTML = errMsg;
            document.salesOrderForm.deliveryTerms.focus();
            return false;
        }
    }
}
function checkValidity(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if (field == 'Contact Person') {
        field_vlaue = document.salesOrderForm.contactPerson.value;
        field_focus = "contactPerson";
    }

    if (field == 'Sales Person') {
        field_vlaue = document.salesOrderForm.salesPerson.value;
        field_focus = "salesPerson";
    }

    if (field == 'Regional Rep') {
        field_vlaue = document.salesOrderForm.regionalRep.value;
        field_focus = "regionalRep";
    }

    if (field == 'End User') {
        field_vlaue = document.salesOrderForm.endUser.value;
        field_focus = "endUser";
    }

    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")"))
        {
            var errMsg = "<li> " + field + " cannot contain #,$,(, and )  Characters";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkSalesCustomer(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if (field == 'Sales Order No') {
        field_vlaue = document.salesOrderForm.salesOrderNo.value;
        field_focus = "salesOrderNo";
    }

    if (field == 'Customer PO No') {
        field_vlaue = document.salesOrderForm.customerPO.value;
        field_focus = "customerPO";
    }

    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")") || (str == "&") || (str == ".") || (str == ",") || (str == " "))
        {
            var errMsg = "<li> " + field + " cannot contain # $ ( ) . , & and space Characters";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkCustomerPONumber(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if (field == 'Sales Order No') {
        field_vlaue = document.salesOrderForm.salesOrderNo.value;
        field_focus = "salesOrderNo";
    }

    if (field == 'Customer PO No') {
        field_vlaue = document.salesOrderForm.customerPO.value;
        field_focus = "customerPO";
    }

    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if (i == 0 && str == " ")
        {
            var errMsg = "* " + field + " cannot start with a space";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")") || (str == "&") || (str == ".") || (str == ","))
        {
            var errMsg = "<li> " + field + " cannot contain # $ ( ) . , and &";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkShipping(field)
{
    var field_vlaue = "";
    var field_focus = "";

    if (field == 'Shipping Account') {
        field_vlaue = document.salesOrderForm.shippingAccount.value;
        field_focus = "shippingAccount";
    }

    if (field == 'New Shipping Method') {
        field_vlaue = document.salesOrderForm.newshippingMethod.value;
        field_focus = "newshippingMethod";
    }

    if (field == 'New Shipping Account') {
        field_vlaue = document.salesOrderForm.newshippingAccount.value;
        field_focus = "newshippingAccount";
    }

    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "$") || (str == "#") || (str == "(") || (str == ")") || (str == "&") || (str == ".") || (str == ","))
        {
            var errMsg = "<li> " + field + " cannot contain # $ ( ) . , and & Characters";
            pa.innerHTML = errMsg;
            var obj = eval("document.salesOrderForm." + field_focus);
            obj.focus();
            return false;
        }
    }
}

function checkForDot(field)
{
    var field_vlaue = document.salesOrderForm.shippingTerms.value;
    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "."))
        {
            var errMsg = "<li> " + field + " cannot contain . Character";
            pa.innerHTML = errMsg;
            document.salesOrderForm.shippingTerms.focus();
            return false;
        }
    }
}

function checkForBraces(field)
{
    var field_vlaue = document.salesOrderForm.deliveryTerms.value;
    var pa = document.getElementById("error");
    pa.innerHTML = "&nbsp;";

    for (i = 0; i < field_vlaue.length; i++)
    {
        var str = field_vlaue.charAt(i)
        if ((str == "(") || (str == ")"))
        {
            var errMsg = "<li> " + field + " cannot contain '(' and ')' Characters";
            pa.innerHTML = errMsg;
            document.salesOrderForm.deliveryTerms.focus();
            return false;
        }
    }
}